package first.program;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;



public class WinScreen extends Activity {
	public static final String PREFS_NAME = "MyPrefsFile"; // Shared Preference File
	private static final int feedbackConstant = 3;
	final CreateGame game = new CreateGame();
	String colors[] = {"green", "orange", "black", "blue","red", "purple","yellow","gray"};
	
	String [] pw;
	String [] passcode = new String[4];
	Boolean rand_setting;
	int mode;
	
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.winscreen);
        Bundle bundle = getIntent().getExtras();{
    		try{
    			mode = bundle.getInt("mode"); 
    			pw = bundle.getStringArray("passcode");
    		}catch(Exception e1){Log.i("Error at bundle ", e1.toString());}}
        
        
        
  	  Button play_again = (Button) findViewById(R.id.playagain);
  	  play_again.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
            	view.performHapticFeedback(feedbackConstant , 0);
            	
                final SharedPreferences settings= getSharedPreferences(PREFS_NAME, 0);
                rand_setting = settings.getBoolean("rand", false);
                
          	if(mode == 1){ 
          		
          		if(rand_setting){
                	Log.i("WinScreen", "Repeats are allowed");
                	game.createRep();
                	passcode = game.getPassword();          	
                	}
                else{
                		Log.i("WinScreen", "wrong! repeats not allowed");
                		game.createNonRep();
                    	passcode = game.getPassword();

                	}
                		
                    Intent myIntent = new Intent(view.getContext(), GameScreen.class);
                    myIntent.putExtra("passcode", passcode);
                    myIntent.putExtra("mode", 1);
                    startActivityForResult(myIntent, 0);
                }         		
          	
          		
          	else if(mode == 0){
          		Intent myIntent = new Intent(view.getContext(), CodeScreen.class);
          		startActivityForResult(myIntent, 0);
          		
          	}
                
            }

        });
  	  
  	  
  	  
  	  
  	  
  	  
  	  Button home_again = (Button) findViewById(R.id.home);
  	   home_again.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {

          		Intent myIntent = new Intent(view.getContext(), MasterMindActivity.class);
          		startActivityForResult(myIntent, 0);
          		
				view.performHapticFeedback(feedbackConstant , 0);
          		
    
                
            }

        });
  	  
        
        
        
    }
    
    @Override
    public void onBackPressed(){
    return;	
    }
}